#define DEBUG

#ifdef DEBUG

#include <stdio.h>

#ifdef WIN32
#define _RDTSC_STACK(ts) \
	__asm rdtsc \
	__asm mov DWORD PTR [ts], eax \
	__asm mov DWORD PTR [ts+4], edx

__inline unsigned __int64 readTimeStampCounter() {
	unsigned __int64 t;
	_RDTSC_STACK(t);
	return t;
}
#else
typedef long long __int64;

inline volatile long long readTimeStampCounter() {
   register long long TSC asm("eax");
   asm volatile (".byte 15, 49" : : : "eax", "edx");
   return TSC;
} 
#endif

class FunctionObject
{
public:
	char *name;
	__int64 executionTime;
	__int64 callCount;

	FunctionObject(char *name);

	char *getName()
	{
		return name;
	}

	static void printProfilingInformation();
};

class FunctionExecutionObject
{
	FunctionObject *function;
	__int64 startTime;
public:
	FunctionExecutionObject(FunctionObject *function);
	~FunctionExecutionObject();
};

#define ENTER(a) static FunctionObject _functionObject(#a); FunctionExecutionObject _functionExecutionObject(&_functionObject);

#else

#define ENTER(a)

#endif

